<template>
	<view>
		<view class="search-box">
			<my-search></my-search>
		</view>
		<swiper class="swiper" circular :indicator-dots="true" :autoplay="true" :interval="5000" :duration="500">
			<swiper-item v-for="item in swiperList" :key="item.goods_id">
				<navigator :url="'/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id" class="swiper-item">
					<img :src="item.image_src">
				</navigator>
			</swiper-item>
		</swiper>

		<view class="nav-list">
			<view class="nav-item" v-for="(item, i) in navList" :key="i" @click="switchToCate(item)">
				<image :src="item.image_src" class="nav-img"></image>
			</view>
		</view>

		<view class="floor">
			<view class="floor-item" v-for="(item,i) in floorList" :key="i">
				<navigator class="floor-title" :url="item.url">
					<img :src="item.floor_title.image_src" :alt="item.floor_title.name">
				</navigator>
				<view class="floor-img">
					<view class="floor-left">
						<image :src="item.product_list[0].image_src" :style="{width:item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
					</view>
					<view class="floor-right">
						<navigator :url="item2.url" class="right-img-item" v-for="(item2, i2) in item.product_list" :key="i2" v-if="i2 !== 0">
							<image :src="item2.image_src" :style="{width:item2.image_width + 'rpx'}" mode="widthFix">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//轮播数据
				swiperList: [],
				//导航数据
				navList: [],
				//楼层数据
				floorList: []
			};
		},
		methods: {
			async getSwiperList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/swiperdata')
				// console.log(res)
				if (res.meta.status !== 200) {
					return uni.$showMsg()
				}
				this.swiperList = res.message
			},
			
			async getNavList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/catitems')
				// console.log(res)
				if (res.meta.status !== 200) return uni.$showMsg()
				this.navList = res.message
			},
			
			//获取楼层数据
			async getFloorList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/floordata')
				if (res.meta.status !== 200) return uni.$showMsg()
				
				res.message.forEach(floor => {
					floor.product_list.forEach(prod => {
						prod.url = '/subpkg/goods_list/goods_list?' + prod.navigator_url.split('?')[1]
					})
				})
				
				this.floorList = res.message
			},
			
			//点击跳转到分类页
			switchToCate(item) {
				if (item.name == '分类') {
					uni.switchTab({
						url: "/pages/cate/cate"
					})
				}
			},
			

		},
		onLoad() {
			this.getSwiperList()
			this.getNavList()
			this.getFloorList()
		}
	}
</script>

<style lang="scss">
	.search-box{
		position: sticky;
		top: -1px;
		z-index: 999;
	}
	
	swiper {
		height: 330rpx;
		margin-top: 26rpx;
		display: flex;
		
		padding: 0 6px;
		// border-radius: 8px;	
	}

	.swiper-item{
		height: 100%;
		width: 100%;
		display: flex;
		box-sizing: border-box;
		padding: 0 4px;
		// border-radius: 8px;
	}
	
	.swiper-item img{
		width: 100%;
		height: 100%;
		border-radius: 8px;
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 15px 0;

		.nav-img {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor-title img {
		height: 60rpx;
		width: 100%;
		display: flex;
		margin: 25rpx 0 10rpx;
	}
	
	.floor-img {
	  display: flex;
	  padding-left: 10rpx;
	}
	
	.floor-right{
		display: flex;
		flex-wrap: wrap;
		justify-content: space-evenly;
	}
</style>
